#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2025/6/20 16:47
# @Author  : Chenmm
# @File    : message.py
# @Software: PyCharm


from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session

from middlewares.mysql.database import create_db
from models.message_schema import *
from models.user_schema import UsernameRole
from methods.user_method import get_current_user
from methods.message_method import add_message_method, view_msg_method, list_msg_method, reback_msg, delete_msg

message_router = APIRouter()


@message_router.post("/", summary="添加留言")
async def add_message(
        message_content: MessageContent,
        user: UsernameRole = Depends(get_current_user),
        db: Session = Depends(create_db)
):
    return add_message_method(message_content, user, db)


@message_router.get("/", summary="查看留言")
async def view_message(
        msg_id: int,
        user: UsernameRole = Depends(get_current_user),
        db: Session = Depends(create_db)
):
    return view_msg_method(msg_id, user, db)


@message_router.get("/list", summary="查询留言列表")
def view_message_list(
        user: UsernameRole = Depends(get_current_user),
        db: Session = Depends(create_db)
):
    return list_msg_method(user, db)


@message_router.post("/reback", summary="回复留言")
def reback(
        reback_message: RebackMessage,
        user: UsernameRole = Depends(get_current_user),
        db: Session = Depends(create_db)
):
    return reback_msg(reback_message, user, db)


@message_router.delete("/", summary="删除留言")
def del_msg(
        msg_id: int,
        user: UsernameRole = Depends(get_current_user),
        db: Session = Depends(create_db)
):
    return delete_msg(msg_id, user, db)